<template>
  <div id="app">
    <div><button @click="isShow = !isShow">显示/隐藏</button></div>
    <!-- mode的作用用来指定哪个动画先执行 -->
    <!-- appear的作用是一开始就有动画 -->
    <transition name="why" mode="out-in" appear>
      <component :is="isShow ? 'home' : 'about'"></component>
    </transition>
  </div>
</template>

<script>
import Home from "./page/Home.vue";
import About from "./page/About.vue";
export default {
  name: "App",
  components: {
    Home,
    About,
  },
  data() {
    return {
      isShow: true,
    };
  },
};
</script>

<style lang="less">
#app {
  width: 200px;
  margin: 0 auto;
}
.title {
  display: inline-block;
}
// 帧动画的代码
.why-enter-active {
  animation: bounce 1s ease;
}
.why-leave-active {
  animation: bounce 1s ease reverse;
}
@keyframes bounce {
  0% {
    transform: scale(0);
  }

  50% {
    transform: scale(1.2);
  }

  100% {
    transform: scale(1);
  }
}
// 过度动画代码
.why-enter-from,
.why-leave-to {
  opacity: 0;
}
.why-enter-active,
.why-leave-active {
  transition: opacity 1s ease;
}
</style>
